<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="java.math.*,com.gouwudai.gobbs.pojo.TbbsClass,com.gouwudai.gobbs.pojo.TbbsTopic,com.gouwudai.gobbs.pojo.TbbsTopicRe,com.gouwudai.gobbs.pojo.TbbsRule" %>
<%@ include file="../common/common.jsp" %>
<%@ include file="user_pass2.jsp" %>
<%
int classId = ParamUtils.getIntParameter(request, "classId", 0);
int topicId =  ParamUtils.getIntParameter(request,"topicId");
int topicReId =  ParamUtils.getIntParameter(request,"topicReId");	//回复ID，如果是帖子则删除整个帖子，如果是单个回复则删除单个回复

IClassService classService = (IClassService)BeanManager.getBean("classService");
TbbsClass currentClass = null;
/***************** 权限验证模块 START *********************/
//判断当前版面是否存在
try
{
	currentClass = classService.load(new Integer(classId));
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的版面不存在或已被删除！");
	return;
}
//判断当前帖子是否存在
ITopicService topicService = (ITopicService)BeanManager.getBean("topicService");
TbbsTopic tbbsTopic = null;

try
{
	tbbsTopic = topicService.load(new Integer(topicId));	
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的主题不存在或已被删除！");
	return;
}
//判断用户类型
IClassUserService classUserService = (IClassUserService)BeanManager.getBean("classUserService");
int operatorType = 0;//当前用户的类型，-1：游客，0：普通，1:发帖人，2：版主
if(classUserService.isClassManager(new Integer(classId),USER_ID))	//验证用户是否为版主
{
	operatorType = 2;
}
else if(0==USER_ID.intValue())	//游客
{
	operatorType = -1;
}
else if(tbbsTopic.getUserId().intValue()==USER_ID.intValue())	//验证用户是否为主题作者
{
	operatorType = 1;
}

if(operatorType<1)	//游客或普通
{
	if(!tbbsTopic.getUserId().equals(userLogin.getUserId()))
	{
		HtmlConst.errors(out,1,"您不能删除他人主题，如果您还没有登陆，请先登陆！");
		return;
	}	
}
else if(operatorType==2)	//版主
{
	userLogin.hasClassPermission(new Integer(classId),3003);	//版主删除文章权限
}
/***************** 权限验证模块 END *********************/
//2.读取主题信息并判断当前主题是否存在 ------------------
ITopicReService topicReService = (ITopicReService)BeanManager.getBean("topicReService");

TbbsTopicRe tbbsTopicRe = null;
try
{
	if(topicReId==0)
		tbbsTopicRe = topicReService.load(tbbsTopic.getTopicReId());
	else
		tbbsTopicRe =  topicReService.load(topicReId);
}
catch(Exception e)
{
	HtmlConst.errors(out,6,"您浏览的主题不存在或已被删除！");
	return;
}
//------------------------------------------------
boolean isTopicFlag = (tbbsTopic.getTopicReId().intValue()==topicReId)?true:false;	//当前的是主题还是回复
String actionName = "删除回复";
if(isTopicFlag)
{	
	actionName = "删除主题";
}
%><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=SYSTITLE%> - <%=actionName %></title>
<meta name="Keywords" content="<%=SYSMETAKEY%>" />
<meta name="Description" content="<%=SYSMETADESC%>" />
<%@ include file="../common/meta.inc" %>
<link rel="stylesheet" type="text/css" href="css/defaultStyle.css" >
<script language="javascript" src="${pageContext.request.contextPath}/scripts/prototype.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/buffalo/buffalo.js"></script>
</head>
<body>
<%@ include file="../common/waiting.inc" %>
<SCRIPT language="javascript">

setStatus('<%=SYSTITLE%> - <%=actionName %>');

var END_POINT="${pageContext.request.contextPath}/buffalo";
var buffalo = new Buffalo(END_POINT);
function doSubmit()
{
	var obj = {};    

	obj[Buffalo.BOCLASS] = "java.util.HashMap";
	
	obj.topicId = <%=topicId%>;	
	obj.topicReId = <%=topicReId%>;	
	obj.title = "<%=tbbsTopicRe.getTitle()%>";
	obj.isTopicFlag = <%=isTopicFlag%>;
	obj.topicUserId = <%=tbbsTopic.getUserId()%>;
	obj.topicReUserLoginId = "<%=tbbsTopicRe.getLoginId()%>";
	obj.userLoginId = "<%=LOGIN_ID%>";
	obj.userLoginIp = "<%=LOGIN_IP%>";
	obj.sendMessageFlag = getRadioValue("sendMessageFlag");
	obj.message = $F("message");	
	
    buffalo.remoteCall("topicServiceAjaxService.deleteTopicLogic",[obj], function(reply) 
    {
        var ret = reply.getResult();
        ajaxSubmit(ret,"删除成功！","back");
    }); 
	
	
}

function showMessage(flag)
{
	var divMessage = $("divMessage");
	if(flag)
	{
		divMessage.style.display = "";		
	}else{
		divMessage.style.display = "none";	
	}
}

function doCancel()
{
	history.back();
}
</SCRIPT>
<DIV class="line"></DIV>
<form name="theform" id="theform" method="post">
<table width="100%" border="0" align="center" cellpadding="4" cellspacing="1" class="tab">
<tr>
	<td align="center" colspan="2">您确认要<%=actionName %> <strong>&lt;&lt;<%=tbbsTopicRe.getTitle() %>&gt;&gt;</strong> 吗？</td>
</tr>
<tr class="tab2">
	<td align="left" class="tab1" width="20%"><strong>是否用短消息通知对方</strong></td>
	<td align="left">
	<input name="sendMessageFlag" type="radio" value="1" onclick="javascript:showMessage(true);"/>通知
	<input name="sendMessageFlag" type="radio" value="0" onclick="javascript:showMessage(false);" checked="checked" />不通知
	<div id="divMessage" style="DISPLAY:none"><textarea name="message" cols="80" rows="6">原因：</textarea></div>
	</td>
</tr>
<tr class="tab2">
<td align="center"  colspan="2">
	<button id="btnSubmit" name="btnSubmit" class="btn" onClick="doSubmit();">确定</button>&nbsp;&nbsp;&nbsp;
	<button id="btnCancel" name="btnCancel" class="btn" onClick="doCancel();">取消</button>
</td></tr></table>
</form>
<%=COPYRIGHTFOOT%>
<%@ include file="../common/foot.inc"%>
</body>
</html>
